using UnityEngine;
using System.Collections;

public class BG_Instru : MonoBehaviour 
{
	private int id = 1;
	private Vector2 screen;

    void Start()
    {
        this.gameObject.AddComponent("MeshRenderer");
        this.gameObject.AddComponent("MeshFilter");

		this.screen.y = GameObject.Find("Main Camera").GetComponent<Camera>().orthographicSize;
		this.screen.x = this.screen.y * GameObject.Find("Main Camera").GetComponent<Camera>().aspect;

        Mesh mesh = Quad.Create(this.screen.x, this.screen.y);

        this.gameObject.GetComponent<MeshFilter>().mesh = mesh;
        this.gameObject.GetComponent<MeshRenderer>().material = AtlasInstru.globalMaterial;
		
		this.transform.position = new Vector3(0, 1, 1);
    }

    public void Update()
	{	
        this.gameObject.GetComponent<MeshFilter>().mesh.uv = new Vector2[]
		{
			new Vector2(AtlasInstru.rects[id].xMin, AtlasInstru.rects[id].yMax),
			new Vector2(AtlasInstru.rects[id].xMax, AtlasInstru.rects[id].yMax),
			new Vector2(AtlasInstru.rects[id].xMax, AtlasInstru.rects[id].yMin),
			new Vector2(AtlasInstru.rects[id].xMin, AtlasInstru.rects[id].yMin)
		};
		
    }
}
